﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace DotNetExtensions.Core.Helpers
{
    public class JsonMethodInvoker : TypeInvoker
    {
        public string Method { get; set; }

        public JsonMethodInvoker()
        {

        }

        public JsonMethodInvoker(TypeInvoker invoker)
        {
            this.Module = invoker.Module;
            this.Clazz = invoker.Clazz;
        }

        public JsonMethodInvoker(Type type) : base(type)
        {

        }
        public JsonMethodInvoker(Type type, string method) : base(type)
        {
            this.Method = method;
        }


        public string ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        public object Invoke(bool ioc = false)
        {
            return base.Invoke(Method, ioc);
        }
        public object Invoke(object[] parameters, bool ioc = false)
        {
            return base.Invoke(Method, ioc, parameters);
        }

        public static JsonMethodInvoker From(string data)
        {
            if (data == null) return null;
            return JsonConvert.DeserializeObject<JsonMethodInvoker>(data);
        }
    }

}
